/**
 * Created by zhangxiaoyu on 16/12/09.
 */
angular.module('hyt.searchCtrl',[])

  .controller('dotCtrl',function($scope,$filter,$ionicModal,Storage,DeptByDivision,$state,$window,$ionicPopup){
    $scope.showloading=true;
    var loginMsg=Storage.get('user');
    $scope.companySearch={
      province:Storage.get('gpsProvince'),
      city:Storage.get('gpsCity'),
      county:Storage.get('gpsArea'),
      userMsg:{
        username:loginMsg.username,
        password:loginMsg.password,
        uuid:loginMsg.uuid
      }
    };
    DeptByDivision.getDeptByDivision(JSON.stringify($scope.companySearch));
    $scope.$on('DeptByDivision.Updated', function() {
      $scope.companyData=DeptByDivision.getResult().rows;
      $scope.showloading=false;
    });
    //下拉刷新
    $scope.doRefresh=function(){
      DeptByDivision.getDeptByDivision(JSON.stringify($scope.companySearch));
      $scope.$broadcast('scroll.refreshComplete');
    };
    $scope.immediatelyOrder=function(id,name){
      $state.go('addOrder',{companyId:id,companyName:name});
    };
    $scope.callPhone = function (mobilePhone) {
      var confirmPopup = $ionicPopup.confirm({
        title:mobilePhone,
        okText:'呼叫',
        cancelText:'取消'
      });
      confirmPopup.then(function(res) {
        if (res) {
          $window.location.href = "tel:" + mobilePhone;
        }else {

        }
      });
    };
  })
